from http.server import HTTPServer, BaseHTTPRequestHandler
from datetime import datetime

class SimpleHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/plain')
        self.end_headers()
        
        # 获取当前时间并格式化
        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        # 构造包含时间的响应消息
        message = f"Hello from server! Current time is: {current_time}\n"
        # 发送响应（需要编码为字节）
        self.wfile.write(message.encode('utf-8'))

if __name__ == "__main__":
    server = HTTPServer(('0.0.0.0', 12345), SimpleHandler)
    print("Server started at http://0.0.0.0:12345")
    server.serve_forever()